﻿<%@ Page Title="Player List" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site.Master" CodeBehind="PlayerList.aspx.vb" Inherits="WSAD_Assignment.PlayerList" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="FeaturedContent" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">

    <h3 class="form-signup-heading">Player List<asp:Label ID="lblClubName" runat="server"></asp:Label></h3>

    <asp:LinkButton ID="btnAddNewPlayer" 
            runat="server"
            CssClass="btn btn-primary"    
            OnClick="btnAddNewPlayer_Click">
            <i aria-hidden="true" class="glyphicon glyphicon-plus"></i> Add New Player
    </asp:LinkButton>

    <asp:LinkButton ID="btnRSSFeed" 
            runat="server"
            CssClass="btn btn-primary"    
            OnClick="btnRSSFeed_Click">
            <i aria-hidden="true" class="glyphicon glyphicon-bullhorn"></i> RSS Feed
    </asp:LinkButton>

    <asp:LinkButton ID="btnBackClub" 
            runat="server"
            Visible="false"
            CssClass="btn btn-default cancel"    
            OnClick="btnBackClub_Click">
            <i aria-hidden="true" class="glyphicon glyphicon-arrow-left"></i> Back to Club
    </asp:LinkButton><br /><br />
    
    <asp:UpdatePanel id="upClubList" runat="server">
        <ContentTemplate>

            <asp:PlaceHolder ID="phSearch" runat="server">
                <asp:TextBox ID="txtSearch" name="txtSearch" runat="server" CssClass="form-control search" placeholder="Player Search" Width="200px"></asp:TextBox>
                <asp:PlaceHolder ID="phSearchButton" runat="server"></asp:PlaceHolder>
                <asp:Button ID="btnSearch" 
                    runat="server"
                    CssClass="btn btn-primary search"
                    Text=" ">
                </asp:Button>
        
                <asp:DropDownList ID="ddlClub" name="ddlClub" runat="server" DataSourceID="ClubsDataSource" DataTextField="ClubName" DataValueField="ClubName" CssClass="form-control search"
                    AppendDataBoundItems="true" AutoPostBack="true" Width="200px">
                    <asp:ListItem Text="All Clubs" Value="" />
                </asp:DropDownList>
                <asp:SqlDataSource ID="ClubsDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:ClubsConnectionString %>" ProviderName="<%$ ConnectionStrings:ClubsConnectionString.ProviderName %>"
                         SelectCommand="SELECT [ClubName] FROM [Clubs]"></asp:SqlDataSource>
        
                <asp:DropDownList ID="ddlPosition" name="ddlPosition" runat="server" DataSourceID="PositionsDataSource" DataTextField="PositionName" DataValueField="PositionName" CssClass="form-control search"
                    AppendDataBoundItems="true" AutoPostBack="true" Width="200px">
                    <asp:ListItem Text="All Positions" Value="" />
                </asp:DropDownList>
                <asp:SqlDataSource ID="PositionsDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:ClubsConnectionString %>" ProviderName="<%$ ConnectionStrings:ClubsConnectionString.ProviderName %>"
                         SelectCommand="SELECT [PositionName] FROM [Positions]"></asp:SqlDataSource>        
       
                <br /><br />
            </asp:PlaceHolder>

            <asp:Panel ID="pnlUserMessage_Error" CssClass="bg-danger" runat="server">
                <asp:Label ID="lblUserMessage_Error" runat="server"></asp:Label>
            </asp:Panel>

            <asp:GridView ID="gvClubPlayerList" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False"
                 DataSourceID="PlayerListDataSource" GridLines="None" PageSize="20"
                 CssClass="table table-hover table-striped table-bordered table-condensed" Visible="false"
                 EmptyDataText="No records found for the search criteria">
                <Columns>
                    <asp:HyperLinkField DataNavigateUrlFields="PlayerID" DataNavigateUrlFormatString="PlayerDetail.aspx?PlayerID={0}" DataTextField="FullName" HeaderText="Full Name" SortExpression="FullName" />
                    <asp:BoundField DataField="PositionName" HeaderText="Position" SortExpression="PositionName" />
                    <asp:TemplateField HeaderText="Profile Picture">
                        <ItemTemplate>
                            <a href='PlayerDetail.aspx?PlayerID=<%# Eval("PlayerID")%>'>
                                <img src='<%# Eval("ProfilePicture") %>' Width="100px" Height="100px" />
                            </a>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>

            <asp:SqlDataSource ID="PlayerListDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:ClubsConnectionString %>" ProviderName="<%$ ConnectionStrings:ClubsConnectionString.ProviderName %>" 
                SelectCommand="SELECT [Clubs.ID] AS ClubID, [Players.ID] AS PlayerID, [FullName], [ClubName], [PositionName], [ProfilePicture] FROM [PlayerList] WHERE ([Clubs.ID] = ?) ORDER BY FullName ASC"
                FilterExpression="([FullName] LIKE '%{0}%') AND ([PositionName] LIKE '%{1}%')">
                <SelectParameters>
                    <asp:QueryStringParameter Name="ClubID" QueryStringField="ClubID" Type="Int32" />
                </SelectParameters>
                <FilterParameters>
                    <asp:ControlParameter Name="FullName" ControlID="txtSearch" PropertyName="Text" ConvertEmptyStringToNull="False"  />
                    <asp:ControlParameter Name="PositionName" ControlID="ddlPosition" PropertyName="SelectedValue" ConvertEmptyStringToNull="False" />
                </FilterParameters>
            </asp:SqlDataSource>

            <asp:GridView ID="gvFullPlayerList" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False"
                 DataSourceID="PlayerListDataSource2" GridLines="None" PageSize="20"
                 CssClass="table table-hover table-striped table-bordered table-condensed" Visible="false"
                 EmptyDataText="No records found for the search criteria">
                <Columns>
                    <asp:HyperLinkField DataNavigateUrlFields="PlayerID" DataNavigateUrlFormatString="PlayerDetail.aspx?PlayerID={0}" DataTextField="FullName" HeaderText="Full Name" SortExpression="FullName" />
                    <asp:BoundField DataField="ClubName" HeaderText="Club" SortExpression="ClubName" />
                    <asp:BoundField DataField="PositionName" HeaderText="Position" SortExpression="PositionName" />
                    <asp:TemplateField HeaderText="Profile Picture">
                        <ItemTemplate>
                            <a href='PlayerDetail.aspx?PlayerID=<%# Eval("PlayerID")%>'>
                                <img src='<%# Eval("ProfilePicture") %>' Width="100px" Height="100px" />
                            </a>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>

            <asp:SqlDataSource ID="PlayerListDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ClubsConnectionString %>" ProviderName="<%$ ConnectionStrings:ClubsConnectionString.ProviderName %>" 
                SelectCommand="SELECT [Clubs.ID] AS ClubID, [Players.ID] AS PlayerID, [FullName], [ClubName], [PositionName], [ProfilePicture] FROM [PlayerList] ORDER BY FullName ASC"
                FilterExpression="([FullName] LIKE '%{0}%') AND ([ClubName] LIKE '%{1}%') AND ([PositionName] LIKE '%{2}%')">
                <FilterParameters>
                    <asp:ControlParameter Name="FullName" ControlID="txtSearch" PropertyName="Text" ConvertEmptyStringToNull="False" />
                    <asp:ControlParameter Name="ClubName" ControlID="ddlClub" PropertyName="SelectedValue" ConvertEmptyStringToNull="False" />
                    <asp:ControlParameter Name="PositionName" ControlID="ddlPosition" PropertyName="SelectedValue" ConvertEmptyStringToNull="False" />
                </FilterParameters>
            </asp:SqlDataSource>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>
